<?php
class LinkModule
{
	function index() {
		global $_G;
		$uid = empty($_GET['uid']) ? 0 : intval($_GET['uid']);
			$where = '';
	        if ($uid){
	        	$where = ' AND l.uid='.$uid;
	        }
        	$cates = $_G['cache']->get('category');
        	$type=1;
	        $limit = 15;
			$links = array();
			$sql = "SELECT l.*,c.catename,u.username FROM ".DB_PREFIX."link l LEFT JOIN ".DB_PREFIX."category c ON l.cid=c.cid LEFT JOIN ".DB_PREFIX."users u ON l.uid=u.uid WHERE l.visible=1 {$where} ORDER BY l.lid DESC ";
			$query = $_G['db']->page_query($sql,$limit);
			$num = $_G['db']->result("SELECT count(*) AS num FROM ".DB_PREFIX."link l LEFT JOIN ".DB_PREFIX."category c ON l.cid=c.cid WHERE l.visible=1 {$where} ORDER BY l.lid DESC ");
			while($data = $_G['db']->fetch_array($query)) {
				$links[] = $data ;
			}
			$pager = pager($num,$limit);
			include template('link');
	}
	function newsl(){
		global $_G;
		$limit = 10;
		$sql = 'SELECT m.*,c.catename FROM'.table('myread').'m LEFT JOIN'.table('category').'c ON m.cid=c.cid WHERE m.recommend=0 '.$where;
		$query = $_G['db']->page_query($sql,$limit);
		$num = $_G['db']->result('SELECT count(1) FROM'.table('myread').'m LEFT JOIN'.table('category').'c ON m.cid=c.cid WHERE m.recommend=0 '.$where);
		while($data = $_G['db']->fetch_array($query)) {
			$datas[] = $data ;
		}
		$return['status'] = true;
		foreach($datas as $data){
			$return['msg'] .= '<li><span style="float:right;">'.gdate('Y-m-d',$data['dateline']).'</span><a rel="nofollow" href="link.php?f=news&id='.$data['rid'].'" target="_blank">'.$data['title'].'</a> <span onclick="$(\'#lkd'.$data['rid'].'\').toggle();" style="font-size:12px;color:#666;cursor:pointer;">[+详细+]</span>
			<p id="lkd'.$data['rid'].'">'.$data['description'].' <a rel="nofollow" href="link.php?f=news&id='.$data['rid'].'" target="_blank">[原文]</a></p></li>';
		}
		print_R(json_encode($return));
		exit;
	}
	function newsr(){
		global $_G;
		$limit = 10;
		$sql = 'SELECT m.*,c.catename FROM'.table('myread').'m LEFT JOIN'.table('category').'c ON m.cid=c.cid WHERE m.recommend=1 '.$where;
		$query = $_G['db']->page_query($sql,$limit);
		$num = $_G['db']->result('SELECT count(1) FROM'.table('myread').'m LEFT JOIN'.table('category').'c ON m.cid=c.cid WHERE m.recommend=1 '.$where);
		while($data = $_G['db']->fetch_array($query)) {
			$datas[] = $data ;
		}
		$return['status'] = true;
		foreach($datas as $data){
			$return['msg'] .= '<li><span style="float:right;">'.gdate('Y-m-d',$data['dateline']).'</span><a rel="nofollow" href="link.php?f=news&id='.$data['rid'].'" target="_blank">'.$data['title'].'</a> <span onclick="$(\'#lkd'.$data['rid'].'\').toggle();" style="font-size:12px;color:#666;cursor:pointer;">[+详细+]</span>
			<p id="lkd'.$data['rid'].'">'.$data['description'].' <a rel="nofollow" href="link.php?f=news&id='.$data['rid'].'" target="_blank">[原文]</a></p></li>';
		}
		print_R(json_encode($return));
		exit;
	}
	function news() {
		global $_G;
		$limit = 14;
		$stand = true;
		$links = array();
		$id = isset($_GET['id'])?intval($_GET['id']):0;
		$where = '';
		if($id) {
			$url = $_G['db']->result("SELECT link FROM".table('myread')."WHERE rid='".$id."'");
			if($url){
				//$_G['db']->query("UPDATE".table('myread')."SET views=views+1 WHERE rid='".$id."'");
				header("location: $url");
			}else{
				exit('此条信息已经删除');
			}
			exit;
		}
		
		$sql = 'SELECT m.*,c.catename FROM'.table('myread').'m LEFT JOIN'.table('category').'c ON m.cid=c.cid WHERE m.recommend=0 '.$where;
		$query = $_G['db']->page_query($sql,$limit);
		$num = $_G['db']->result('SELECT count(1) FROM'.table('myread').'m LEFT JOIN'.table('category').'c ON m.cid=c.cid WHERE m.recommend=0 '.$where);
		while($data = $_G['db']->fetch_array($query)) {
			$datas[] = $data ;
		}
		$pager = pager($num,$limit);
				
				
				$sql = 'SELECT m.*,c.catename FROM'.table('myread').'m LEFT JOIN'.table('category').'c ON m.cid=c.cid WHERE m.recommend=1 '.$where;
				$query = $_G['db']->page_query($sql,$limit);
				$num = $_G['db']->result('SELECT count(1) FROM'.table('myread').'m LEFT JOIN'.table('category').'c ON m.cid=c.cid WHERE m.recommend=1 '.$where);
				while($data1 = $_G['db']->fetch_array($query)) {
					$datas1[] = $data1 ;
				}
				$pager1 = pager($num,$limit);
				include template('link');
				
		
	}

}	